<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>
    <style>
        body {
    font-family: 'Arial', sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
}

hr {
    border: 0;
    height: 1px;
    background-color: #ccc;
    margin: 20px 0;
}

a {
    text-decoration: none;
    color: #007bff;
}

a:hover {
    text-decoration: underline;
}
</style>
</head>
<body>
    <h2>商品列表</h2>
    <hr>
    <form action="" method="get">
        {% csrf_token %}
        <button type="submit" name="sort_by" value="name">按名称排序</button>
        <button type="submit" name="sort_by" value="price">按价格排序</button>
    </form>
    <ul>
        {% for product in products %}
            <li>
                <form action="{% url 'product:product_add' product.id %}" method="post">
                    {% csrf_token %}
                    <input type="hidden" name="pid" value="{{ product.id }}">
                    <p>
                        {{ product.name }} - {{ product.price }} 元/瓶
                        <input type="number" name="num" value="1" min="1">
                    </p>
                    <button type="submit">添加到购物车</button>
                </form>
            </li>
        {% endfor %}
    </ul>
    <a href="{% url 'cart:cart' %}">前往购物车</a>
</body>
</html>